﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;
using System.Collections.Specialized;
using System.Data.SqlClient;
using System.Data;

namespace POSSystem.BLL
{
    public class View_WebProducts : _View_WebProducts
    {
        public static View_WebProducts LoadProductByID(int id)
        {
            try
            {
                View_WebProducts p = new View_WebProducts();
                p.Where.ID.Value = id;
                p.Query.Load();

                return p;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_WebProducts.cs", "LoadProductByID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_WebProducts LoadProductByIDs(string ids)
        {
            try
            {
                View_WebProducts p = new View_WebProducts();
                p.Where.ID.Value = ids;
                p.Where.ID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.In;
                p.Query.Load();

                return p;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_WebProducts.cs", "LoadProductByID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_WebProducts LoadHomeProduct()
        {
            try
            {
                View_WebProducts p = new View_WebProducts();
                p.Where.IsHomeProduct.Value = true;
                p.Where.BranchID.Value = Branches.CurrentBranchID;
                p.Query.Load();

                return p;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_WebProducts.cs", "LoadHomeProduct", ex.StackTrace);
                throw ex;
            }
        }

        public static View_WebProducts LoadDailySpecial(int numberOfItems)
        {
            try
            {
                View_WebProducts p = new View_WebProducts();
                p.Where.IsHotProduct.Value = true;
                p.Where.BranchID.Value = Branches.CurrentBranchID;
                if(numberOfItems > 0)
                    p.Query.Top = numberOfItems;
                p.Query.Load();

                return p;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_WebProducts.cs", "LoadHomeProduct", ex.StackTrace);
                throw ex;
            }
        }

        public static View_WebProducts LoadNewProducts(int numberOfItems)
        {
            try
            {
                View_WebProducts p = new View_WebProducts();
                p.Where.IsNewArrival.Value = true;
                p.Where.BranchID.Value = Branches.CurrentBranchID;
                if (numberOfItems > 0)
                    p.Query.Top = numberOfItems;
                p.Query.Load();

                return p;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_WebProducts.cs", "LoadHomeProduct", ex.StackTrace);
                throw ex;
            }
        }
    }
}
